/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * @author yaoyuming
 * @date  2020-04-20 18:08
 */
package com.yao.ro.mapper.sql;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yao.ro.entity.dto.GoodsDto;

import java.util.Objects;

/**
 * @author yaoyuming
 * @date 2020/04/20 18:08
 */
public class GoodsWrapper {


    /**
     * 功能描述 : 名称模糊匹配
     * @param name
     * @author yaoyuming
     * @date 2020/4/14
     * @return {@link Wrapper < GoodsDto>}
     */
    public static Wrapper<GoodsDto> likeName(String name){
        LambdaQueryWrapper<GoodsDto> wrapper = Wrappers.lambdaQuery();
        wrapper.likeRight(StrUtil.isNotEmpty(name), GoodsDto::getName, name);

        wrapper.select(GoodsDto::getId, GoodsDto::getName);

        return wrapper;
    }

    /**
      * 功能描述 : 名称全匹配
      * @param name
      * @author yaoyuming
      * @date 2020/5/21 0021
      * @return {@link Wrapper< GoodsDto>}
      */
    public static Wrapper<GoodsDto> byName(String name){

        LambdaQueryWrapper<GoodsDto> wrapper = Wrappers.lambdaQuery();
        wrapper.likeRight(StrUtil.isNotEmpty(name), GoodsDto::getName, name);

        wrapper.select(GoodsDto::getId, GoodsDto::getName);

        return wrapper;
    }


    public static Wrapper<GoodsDto> byCondition(GoodsDto dto){

        LambdaQueryWrapper<GoodsDto> wrapper = Wrappers.lambdaQuery();
        wrapper.likeRight(StrUtil.isNotEmpty(dto.getName()), GoodsDto::getName, dto.getName())
                .eq(Objects.nonNull(dto.getType()), GoodsDto::getType, dto.getType());

        wrapper.select(GoodsDto::getId, GoodsDto::getName);

        return wrapper;
    }
}